/**   
* @Title: PublicController.java 
* @Package com.zjdiepu.www.manage.api.zpp 
* 
* @author zhangpp
* @date 2017年5月26日 上午10:31:27 
* @version V1.0   
*/
package com.zjdiepu.www.manage.api.zpp.controller;

import io.swagger.annotations.Api;

import java.io.File;
import java.util.Map;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

import com.zjdiepu.www.base.BaseController;
import com.zjdiepu.www.base.core.AbstractSysUser;
import com.zjdiepu.www.common.util.UUIDFactory;
import com.zjdiepu.www.ibiz.zpp.YwShouLiService;
import com.zjdiepu.www.model.zpp.pub.dot.FilePath;

/**      
 * 项目名称：diepu-parent-manage   
 * 类名称：PublicController   
 * 类描述：   
 * 创建人：zhangpp
 * 创建时间：2017年5月26日 上午10:31:27   
 * 修改人：zhangpp
 * 修改时间：2017年5月26日 上午10:31:27   
 * 修改备注：   
 * @version V1.0     
 */
@RestController
@RequestMapping(value= "PublicController", produces="application/json;charset=UTF-8")
@Api(tags = {"作者：张鹏鹏，电话：15158822934"}, produces="application/json;charset=UTF-8")
public class PublicController extends BaseController
{

	@Resource
	private YwShouLiService ywShouLiService;
	
	/**
	* 上传文件 
	*  @author  zhangpp
	*  @Title:  uploadFile  
	*    
	*  @param  @param request
	*  @param  @param response
	*  @param  @param uploadfile
	*  @param  @return        设定文件  
	*  @return  Map<String,Object>        返回类型  
	*  @version  V1.0
	*  @throws
	 */
    @RequestMapping(value="uploadFile",method = RequestMethod.POST, produces="application/json;charset=UTF-8")
	public Map<String, Object> uploadFile(HttpServletRequest request,HttpServletResponse response,@RequestParam("uploadfile") MultipartFile uploadfile)
	{
		Map<String, Object> maps = success();
		try 
		{
			AbstractSysUser currentUser = getCurrentUser();
			String uuid = UUIDFactory.getUUID();
			File targetFile = new File(FilePath.getFilePath(),uuid+".xlsx");  
	        if(!targetFile.exists())
	        {  
	            targetFile.mkdirs();  
	        }  
	        uploadfile.transferTo(targetFile);  
	        String path = FilePath.getFilePath()+uuid+".xlsx";
	        ywShouLiService.diepuBankFileUpload(currentUser, path);
	        
	        String fileName = uploadfile.getOriginalFilename();
	        maps.put("fileName", fileName);
		} 
		catch (Exception e) 
		{
			
			maps.put("flag", 100200);
			maps.put("message", e.getMessage());
			
			String fileName = uploadfile.getOriginalFilename();
	        maps.put("fileName", fileName);
			maps.put("fileName", fileName);
			return maps;
		}
		return maps;
	}
}
